#ifndef AP_INCLUDED
#define AP_INCLUDED

#include "fmt.h"

#define T AP_T // Arbitrary Precision, support signed integers
typedef struct T *T;

T    AP_new(long n);
void AP_free(T *z);

T     AP_fromstr(const char *str, int base, char **end);
long  AP_toint(T x);
char* AP_tostr(char *str, int size, int base, T x);
void  AP_fmt(int code, va_list_box *box,
             int put(int c, void *cl), void *cl,
             unsigned char flags[256], int width, int precision);

int AP_cmp(T x, T y);
int AP_cmpi(T x, long y);

T AP_neg(T x);
T AP_add(T x, T y);
T AP_sub(T x, T y);
T AP_mul(T x, T y);
T AP_div(T x, T y);
T AP_mod(T x, T y);
T AP_pow(T x, T y, T p);

T    AP_addi(T x, long y);
T    AP_subi(T x, long y);
T    AP_muli(T x, long y);
T    AP_divi(T x, long y);
long AP_modi(T x, long y);

T AP_lshift(T x, int s);
T AP_rshift(T x, int s);

#undef T

#endif

